package controller;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	public static void main(String[] args) {
		try {
			//
			// Create a connection to the server socket on the server application
			//
			InetAddress host = InetAddress.getLocalHost();
			Socket socket = new Socket(host.getHostName(), 7777);

			//
			// Send a message to the client application
			//
			ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
			System.out.println("Wysyłam Agnieszka");
			oos.writeObject("Agnieszka");

			//
			// Read and display the response message sent by server application
			//
			ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
			String message = (String) ois.readObject();
			System.out.println("Otrzymuję: " + message);

			ois.close();
			oos.close();
		}
		catch (UnknownHostException e) {
			e.printStackTrace();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
